/**
* @license
* Copyright (c) 2014, 2018, Oracle and/or its affiliates.
* The Universal Permissive License (UPL), Version 1.0
*/
"use strict";define(["ojs/ojcore","jquery","promise","ojs/ojcomponentcore","ojs/ojpopupcore","ojs/ojanimation"],function(e,t){var i,s,o={properties:{autoDismiss:{type:"string",enumValues:["focusLoss","none"],value:"focusLoss"},chrome:{type:"string",enumValues:["default","none"],value:"default"},initialFocus:{type:"string",enumValues:["auto","firstFocusable","none","popup"],value:"auto"},modality:{type:"string",enumValues:["modal","modeless"],value:"modeless"},position:{type:"object",properties:{at:{type:"object",properties:{horizontal:{type:"string",enumValues:["center","end","left","right","start"],value:"start"},vertical:{type:"string",enumValues:["bottom","center","top"],value:"top"}}},collision:{type:"string",enumValues:["fit","flip","flipcenter","flipfit","none"],value:"flip"},my:{type:"object",properties:{horizontal:{type:"string",enumValues:["center","end","left","right","start"],value:"start"},vertical:{type:"string",enumValues:["bottom","center","top"],value:"top"}}},of:{type:"string|object"},offset:{type:"object",properties:{x:{type:"number",value:0},y:{type:"number",value:0}}}}},tail:{type:"string",enumValues:["none","simple"],value:"none"},translations:{type:"object",value:{}}},methods:{open:{},close:{},isOpen:{},refresh:{},setProperty:{},getProperty:{},setProperties:{},getNodeBySubId:{},getSubIdByNode:{}},events:{ojBeforeOpen:{},ojOpen:{},ojBeforeClose:{},ojClose:{},ojFocus:{},ojAnimateStart:{},ojAnimateEnd:{}},extension:{}};i=["oj-left","oj-center","oj-right","oj-top","oj-middle","oj-bottom"],s={"right-top":"oj-right oj-top","right-middle":"oj-right oj-middle","right-bottom":"oj-right oj-bottom","left-top":"oj-left oj-top","left-middle":"oj-left oj-middle","left-bottom":"oj-left oj-bottom","center-top":"oj-center oj-top","center-middle":"oj-left oj-middle","center-bottom":"oj-center oj-bottom"},e.__registerWidget("oj.ojPopup",t.oj.baseComponent,{widgetEventPrefix:"oj",options:{animation:null,autoDismiss:"focusLoss",chrome:"default",initialFocus:"auto",position:{my:{horizontal:"start",vertical:"top"},offset:{x:0,y:0},at:{horizontal:"start",vertical:"bottom"},of:void 0,collision:"flip"},tail:"none",modality:"modeless",role:"tooltip",beforeOpen:null,open:null,beforeClose:null,close:null,focus:null,animateStart:null,animateEnd:null},_ComponentCreate:function(){this._super();var i=this._getRootStyle(),s=this.element;s.hide().addClass(i).attr("aria-hidden","true"),s.addClass("oj-component");var o=t("
");o.addClass([i,"content"].join("-")),o.attr("role","presentation"),o.append(s[0].childNodes),o.appendTo(s),this._content=o,this._setChrome(),this._setupFocus(s);var n=this.options;n.position=e.PositionUtils.coerceToJet(n.position)},_AfterCreate:function(){this._super(),this.element.uniqueId(),this._createTail()},_destroy:function(){e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN&&this._closeImplicitly(),this._setWhenReady("none"),this._destroyTail(),delete this._popupServiceEvents;var t=this.element;t.hide().attr("aria-hidden","true").removeUniqueId();var i=this._content;delete this._content,t.append(i[0].childNodes),i.remove();var s=this._closeDelayTimer;s&&(delete this._closeDelayTimer,s()),this._super()},open:function(t,i){if(!this._isOperationPending("open",[t,i])){e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN&&this._closeImplicitly(),this._setLauncher(t);var s=this.element;if(t=this._launcher,!1!==this._trigger("beforeOpen")){this._setWhenReady("open");var o=this.options;(i=i||o.position).of||(this._hasPositionOfLauncherOverride=!0,i.of=t),this._setPosition(i),this._setAutoDismiss(o.autoDismiss),this._addDescribedBy(),this._IsCustomElement()&&s[0].hasAttribute("role")||s.attr("role",o.role),i=this._getPositionAsJqUi();var n=this._getRootStyle(),r=[n,"layer"].join("-"),a=o.tail;"none"!==a&&(r+=" "+[n,"tail",a].join("-"));var l={};l[e.PopupService.OPTION.POPUP]=s,l[e.PopupService.OPTION.LAUNCHER]=t,l[e.PopupService.OPTION.POSITION]=i,l[e.PopupService.OPTION.EVENTS]=this._getPopupServiceEvents(),l[e.PopupService.OPTION.LAYER_SELECTORS]=r,l[e.PopupService.OPTION.MODALITY]=o.modality,l[e.PopupService.OPTION.CUSTOM_ELEMENT]=this._IsCustomElement(),e.PopupService.getInstance().open(l)}}},_beforeOpenHandler:function(t){var i=t[e.PopupService.OPTION.POPUP],s=t[e.PopupService.OPTION.POSITION];i.show(),i.position(s);var o=this.options.animation;if(o&&o.open){var n=o.actionPrefix,r=n?[n,"open"].join("-"):"open";return e.AnimationUtils.startAnimation(i[0],r,e.PositionUtils.addTransformOriginAnimationEffectsOption(i,o.open),this)}},_afterOpenHandler:function(t){var i=t[e.PopupService.OPTION.POPUP],s=t[e.PopupService.OPTION.LAUNCHER];this._initVoiceOverAssist(),this._trigger("open"),this._intialFocus(),this._on(i,{keydown:this._keyHandler,keyup:this._keyHandler}),s&&s.length>0&&this._on(s,{keydown:this._keyHandler,keyup:this._keyHandler})},_GetContextMenu:function(){if(!this._IsCustomElement())return this._super();var t=e.BaseCustomElementBridge.getSlotMap(this._content[0]).contextMenu;return t&&t.length>0?t[0]:void 0},close:function(){if(!this._isOperationPending("close",[])&&e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN&&(!1!==this._trigger("beforeClose")||this._ignoreBeforeCloseResultant)){this._setWhenReady("close"),this._restoreFocus();var t=this._launcher,i=this.element;this._off(i,"keydown keyup"),t&&t.length>0&&this._off(t,"keydown keyup"),this._destroyVoiceOverAssist();var s={};s[e.PopupService.OPTION.POPUP]=i,e.PopupService.getInstance().close(s)}},_beforeCloseHandler:function(t){var i=t[e.PopupService.OPTION.POPUP],s=this.options.animation;if(!this._ignoreBeforeCloseResultant&&s&&s.close){var o=i.attr("style"),n=s.actionPrefix,r=n?[n,"close"].join("-"):"close";return e.AnimationUtils.startAnimation(i[0],r,e.PositionUtils.addTransformOriginAnimationEffectsOption(i,s.close),this).then(function(){i.attr("style",o),i.hide()})}i.hide()},_afterCloseHandler:function(e){this._removeDescribedBy(),this._setAutoDismiss(),delete this._launcher,this._trigger("close"),this._hasPositionOfLauncherOverride&&(this.options.position.of=null,delete this._hasPositionOfLauncherOverride)},isOpen:function(){var t=e.ZOrderUtils.getStatus(this.element);return t===e.ZOrderUtils.STATUS.OPENING||t===e.ZOrderUtils.STATUS.OPEN||t===e.ZOrderUtils.STATUS.CLOSING},refresh:function(){if(this._super(),e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN&&this._reposition()){var t=this.element;e.PopupService.getInstance().triggerOnDescendents(t,e.PopupService.EVENT.POPUP_REFRESH)}},_setOption:function(t,i){var s=this.options;switch(t){case"tail":i!==s.tail&&this._setTail(i);break;case"chrome":i!==s.chrome&&this._setChrome(i);break;case"position":return this._setPosition(i),void this.refresh();case"autoDismiss":e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN&&i!==s.autoDismiss&&this._setAutoDismiss(i);break;case"modality":if(e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN){var o=this.element,n={};n[e.PopupService.OPTION.POPUP]=o,n[e.PopupService.OPTION.MODALITY]=i,e.PopupService.getInstance().changeOptions(n)}}this._superApply(arguments)},_getRootStyle:function(){return"oj-popup"},_setTail:function(e){this._destroyTail(),this._createTail(e),this._reposition()},_createTail:function(i){var s=i||this.options.tail;if("none"!==s){var o=this._getRootStyle(),n=[o,"tail"].join("-"),r=[n,s].join("-"),a=t("
").hide();a.addClass(n).addClass(r),a.attr("role","presentation"),this._tailId=a.attr("id",this._getSubId("tail")).attr("id");var l=this.element;if(a.appendTo(l),l.addClass(r),e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN){var u=[o,"layer"].join("-");u+=" "+r;var c={};c[e.PopupService.OPTION.POPUP]=l,c[e.PopupService.OPTION.LAYER_SELECTORS]=u,e.PopupService.getInstance().changeOptions(c)}}},_getTail:function(){var e=this._tailId;return e?t(document.getElementById(e)):null},_destroyTail:function(){var t=this._getTail();t&&t.remove(),delete this._tailId;var i=this.options.tail,s=this._getRootStyle(),o=[s,"tail",i].join("-"),n=this.element;if(n.removeClass(o),e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN){var r=[s,"layer"].join("-"),a={};a[e.PopupService.OPTION.POPUP]=n,a[e.PopupService.OPTION.LAYER_SELECTORS]=r,e.PopupService.getInstance().changeOptions(a)}},_setChrome:function(e){var t=e||this.options.chrome,i=[this._getRootStyle(),"no-chrome"].join("-"),s=this.element;"default"===t&&s.hasClass(i)?s.removeClass(i):"none"!==t||s.hasClass(i)||s.addClass(i)},_setLauncher:function(i){if(i?"string"===t.type(i)?i=t(i):1===i.nodeType&&(i=t(i)):i=t(document.activeElement),i instanceof t&&i.length>1)for(var s=this.element,o=0;o0){var r=n[0],a=n[n.length-1],l=this.element;r!==o&&l[0]!==o||!e.shiftKey?a!==o||e.shiftKey||(e.preventDefault(),a===r?(l.attr("tabindex","-1"),l.focus()):t(r).focus()):(e.preventDefault(),r===a&&r===o?(l.attr("tabindex","-1"),l.focus()):t(a).focus())}else e.preventDefault(),"modeless"===this.options.modality?this._launcher.focus():this.close()}}},_setAutoDismiss:function(t){var i=this._focusLossCallback,s=this._getPopupServiceEvents();if(i&&(delete s[e.PopupService.EVENT.POPUP_AUTODISMISS],delete this._focusLossCallback),"focusLoss"===t&&(i=this._focusLossCallback=this._dismissalHandler.bind(this),s[e.PopupService.EVENT.POPUP_AUTODISMISS]=i),e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN){var o=this.element,n={};n[e.PopupService.OPTION.POPUP]=o,n[e.PopupService.OPTION.EVENTS]=s,e.PopupService.getInstance().changeOptions(n)}},_dismissalHandler:function(t){if(e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN){var i=this._launcher,s=this.element.parent(),o=t.target,n=this._focusSkipLink;if(n){var r=n.getLink();if(r&&e.DomUtils.isAncestorOrSelf(r[0],o))return}if(!e.DomUtils.isAncestorOrSelf(i[0],o)&&!e.DomUtils.isAncestorOrSelf(s[0],o)){if(e.FocusUtils.isFocusable(o)){if("mousedown"===t.type||"touchstart"===t.type)return;this._ignoreRestoreFocus=!0}this.close()}}},_addDescribedBy:function(){var e=this._launcher,i=this.element.attr("id"),s=e.attr("aria-describedby"),o=s?s.split(/\s+/):[];o.push(i),s=t.trim(o.join(" ")),e.attr("aria-describedby",s)},_removeDescribedBy:function(){var e=this._launcher,i=this.element;if(e&&0!==e.length){var s=i.attr("id"),o=e.attr("aria-describedby"),n=o?o.split(/\s+/):[],r=t.inArray(s,n);-1!==r&&n.splice(r,1),(o=t.trim(n.join(" ")))?e.attr("aria-describedby",o):e.removeAttr("aria-describedby")}},_initVoiceOverAssist:function(){var t,i=e.AgentUtils.getAgentInfo().os===e.AgentUtils.OS.IOS||e.AgentUtils.getAgentInfo().os===e.AgentUtils.OS.ANDROID,s=this._liveRegion;s||(s=this._liveRegion=new e.PopupLiveRegion);var o=this._deriveInitialFocus();if(t=i?this.getTranslatedString("none"===o?"ariaLiveRegionInitialFocusNoneTouch":"ariaLiveRegionInitialFocusFirstFocusableTouch"):this.getTranslatedString("none"===o?"ariaLiveRegionInitialFocusNone":"ariaLiveRegionInitialFocusFirstFocusable"),s.announce(t),i){var n=this._getSubId("focusSkipLink"),r=this._launcher,a=this._intialFocus.bind(this,!0);t=this.getTranslatedString("ariaFocusSkipLink"),this._focusSkipLink=new e.PopupSkipLink(r,t,a,n);var l=this._content,u=this._getSubId("closeSkipLink");a=this._closeImplicitly.bind(this),t=this.getTranslatedString("ariaCloseSkipLink"),this._closeSkipLink=new e.PopupSkipLink(l,t,a,u)}},_destroyVoiceOverAssist:function(){this._liveRegion.destroy(),delete this._liveRegion;var e=this._focusSkipLink;e&&(e.destroy(),delete this._focusSkipLink);var t=this._closeSkipLink;t&&(t.destroy(),delete this._closeSkipLink)},_getSubId:function(t){var i=this.element.attr("id");return e.StringUtils.isEmptyOrUndefined(i)&&(i=this.uuid),[i,t].join("_")},_surrogateRemoveHandler:function(){this.element.remove()},_getPopupServiceEvents:function(){if(!this._popupServiceEvents){var t=this._popupServiceEvents={};t[e.PopupService.EVENT.POPUP_CLOSE]=this._closeImplicitly.bind(this),t[e.PopupService.EVENT.POPUP_REMOVE]=this._surrogateRemoveHandler.bind(this),t[e.PopupService.EVENT.POPUP_REFRESH]=this.refresh.bind(this),t[e.PopupService.EVENT.POPUP_BEFORE_OPEN]=this._beforeOpenHandler.bind(this),t[e.PopupService.EVENT.POPUP_AFTER_OPEN]=this._afterOpenHandler.bind(this),t[e.PopupService.EVENT.POPUP_BEFORE_CLOSE]=this._beforeCloseHandler.bind(this),t[e.PopupService.EVENT.POPUP_AFTER_CLOSE]=this._afterCloseHandler.bind(this)}return this._popupServiceEvents},_closeImplicitly:function(){this._ignoreBeforeCloseResultant=!0,this.close(),delete this._ignoreBeforeCloseResultant},_setWhenReady:function(t){var i=this._whenReadyMediator;i&&(i.destroy(),delete this._whenReadyMediator),["open","close"].indexOf(t)<0||(this._whenReadyMediator=new e.PopupWhenReadyMediator(this.element,t,"ojPopup",this._IsCustomElement()))},_isOperationPending:function(e,t){var i=this._whenReadyMediator;return!!i&&i.isOperationPending(this,e,e,t)},_setupFocus:function(e){var i=this;this._focusable({applyHighlight:!0,setupHandlers:function(s,o){i._on(e,{focus:function(e){s(t(e.currentTarget))},blur:function(e){o(t(e.currentTarget))}})}})},_NotifyDetached:function(){e.ZOrderUtils.getStatus(this.element)===e.ZOrderUtils.STATUS.OPEN&&this._closeImplicitly(),this._super()}}),e.Components.setDefaultOptions({ojPopup:{modality:e.Components.createDynamicPropertyGetter(function(){return(e.ThemeUtils.parseJSONFromFontFamily("oj-popup-option-defaults")||{}).modality}),animation:e.Components.createDynamicPropertyGetter(function(){return(e.ThemeUtils.parseJSONFromFontFamily("oj-popup-option-defaults")||{}).animation})}}),o.extension._WIDGET_NAME="ojPopup",e.CustomElementBridge.registerMetadata("oj-popup","baseComponent",o),e.CustomElementBridge.register("oj-popup",{metadata:e.CustomElementBridge.getMetadata("oj-popup")})});